package com.company.entity;

import com.company.utils.MyDateUtil;
import org.apache.logging.log4j.core.pattern.FormattingInfo;
import org.junit.Test;

import java.util.List;
import java.util.Random;

/**
 * 订单类
 */
public class Order {
    private String senderInfo;//寄件人信息
    private String recipientInfo;//收件人信息
    private String pickupType;//寄件方式
    private String itemType;//物品类型
    private String time;//取件时间
    private int weight;//物品预估重量
    private boolean supportValue;//是否保价
    private int price;//物品估价
    private double valuationFee;//保价费
    private String trackingNumber;//快递单号
    public String pickupDate = MyDateUtil.getDate();//寄件日期
    private int modifyCount = 0;//信息修改次数
    public Order() {
    }

    public Order(String senderInfo, String recipientInfo, String pickupType, String itemType, String time, int weight, boolean supportValue) {
        this.senderInfo = senderInfo;
        this.recipientInfo = recipientInfo;
        this.pickupType = pickupType;
        this.itemType = itemType;
        this.time = time;
        this.weight = weight;
        this.supportValue = supportValue;
    }

    public String getSenderInfo() {
        return senderInfo;
    }

    public void setSenderInfo(String senderInfo) {
        this.senderInfo = senderInfo;
    }

    public String getRecipientInfo() {
        return recipientInfo;
    }

    public void setRecipientInfo(String recipientInfo) {
        this.recipientInfo = recipientInfo;
    }

    public String getPickupType() {
        return pickupType;
    }

    public void setPickupType(String pickupType) {
        this.pickupType = pickupType;
    }

    public String getItemType() {
        return itemType;
    }

    public void setItemType(String itemType) {
        this.itemType = itemType;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    public boolean isSupportValue() {
        return supportValue;
    }

    public void setSupportValue(boolean supportValue) {
            this.supportValue = supportValue;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public int getModifyCount() {
        return modifyCount;
    }

    public void setModifyCount(int modifyCount) {
        this.modifyCount = modifyCount;
    }

    public double total(){
        double totalPrice = 0;
        if (this.getWeight()==1){
            totalPrice = 10;
        }else if (this.getWeight()>1){
            totalPrice = 10+(this.getWeight()-1)*3;
        }
        return totalPrice;
    }
    //生成快递单号

    public void setTrackingNumber() {
        Random random = new Random();
        String trackingNumber = "";
        for (int i = 0; i <12 ; i++) {
            int n = random.nextInt(10);
            trackingNumber+=n;
        }
        this.trackingNumber = trackingNumber;
    }

    public String getTrackingNumber() {
        return trackingNumber;
    }

    //计算保价费
    public double valuationFee(){
        valuationFee = this.getPrice() * 0.005;
        return valuationFee;
    }
    public void showInfo() {
        setTrackingNumber();
        System.out.println("------寄件信息------");
        System.out.println("快递单号: "+this.getTrackingNumber());
        System.out.println("取件人信息: "+this.getRecipientInfo());
        System.out.println("物品类型: "+this.getItemType());
        System.out.println("物品重量: "+this.getWeight());
        System.out.println("估价(元): "+this.getPrice()+",保价费(元): "+valuationFee());
        System.out.println("总价(元): "+(total()+valuationFee()));
        System.out.println("寄件日期: "+ pickupDate);
        System.out.println("取件方式: "+this.getPickupType());
    }
}
